next up previous contents index
Next: Character types Up: Types Previous: Types

Base types

The base or simple types of Free Pascal are the Delphi types. We will discuss each separate.


Simple types

syntdiag1072

syntdiag1076

Ordinal types

With the exception of Real types, all base types are ordinal types.

Ordinal types have the following characteristics:

  1. Ordinal types are countable and ordered, i.e. it is, in principle, possible to start counting them one bye one, in a specified order. This property allows the operation of functions as Inc, Ord, Dec on ordinal types to be defined.
  2. Ordinal values have a smallest possible value. Trying to apply the Pred function on the smallest possible value will generate a range check error.
  3. Ordinal values have a largest possible value. Trying to apply the Succ function on the larglest possible value will generate a range check error.

Integers

A list of pre-defined ordinal types is presented in table (gif)

  

Name
Integer
Shortint
SmallInt
Longint
Byte
Word
Cardinal
Boolean
ByteBool
LongBool
Char
Table: Predefined ordinal types

The integer types, and their ranges and sizes, that are predefined in Free Pascal are listed in table (gif).

  

Type Range Size in bytes
Byte 0 .. 255 1
Shortint -127 .. 127 1
Integer -32768 .. 32767 2
Word 0 .. 65535 2
Longint -2147483648 .. 2147483648 4
Cardinalgif 0..4294967296 4
Table: Predefined integer types

Free Pascal does automatic type conversion in expressions where different kinds of integer types are used.

Boolean types

Free Pascal supports the Boolean type, with its two pre-defined possible values True and False, as well as the ByteBool, WordBool and LongBool. These are the only two values that can be assigned to a Boolean type. Of course, any expression that resolves to a boolean value, can also be assigned to a boolean type.

  

Name Size Ord(True)
Boolean 1 1
ByteBool 1 Any nonzero value
WordBool 2 Any nonzero value
LongBool 4 Any nonzero value
Table: Boolean types

Assuming B to be of type Boolean, the following are valid assignments:
listing1021
Boolean expressions are also used in conditions.

Remark: In Free Pascal, boolean expressions are always evaluated in such a way that when the result is known, the rest of the expression will no longer be evaluated (Called short-cut evaluation). In the following example, the function Func will never be called, which may have strange side-effects.
listing1026
Here Func is a function which returns a Boolean type.

Remark: The wordbool, longbool and bytebool were not supported by Free Pascal until version 0.99.6.

Enumeration types

Enumeration types are supported in Free Pascal. On top of the Turbo Pascal implementation, Free Pascal allows also a C-style extension of the enumeration type, where a value is assigned to a particular element of the enumeration list.


Enumerated types

syntdiag1184

syntdiag1188

syntdiag1192

(see chapter (gif) for how to use expressions) When using assigned enumerated types, the assigned elements must be in ascending numerical order in the list, or the compiler will complain.

The expressions used in assigned enumerated elements must be known at compile time.

So the following is a correct enumerated type declaration:
listing1133

The C style enumeration type looks as follows:
listing1135
As a result, the ordinal number of forty is 40, and not 3, as it would be when the ':= 40' wasn't present.

When specifying such an enumeration type, it is important to keep in mind that you should keep initialized set elements in ascending order. The following will produce a compiler error:


listing1143
It is necessary to keep forty and thirty in the correct order.

When using enumeration types it is important to keep the following points in mind:

  1. You cannot use the Pred and Succ functions on this kind of enumeration types. If you try to do that, you'll get a compiler error.
  2. Enumeration types are by default stored in 4 bytes. You can change this behaviour with the {$PACKENUM n} compiler directive, which tells the compiler the minimal number of bytes to be used for enumeration types. For instance
    listing1151
    will, when run, print the following:
    Small enum : 1
    Large enum : 4
More information can be found in the Programmer's guide in the compiler directives section.

Subrange types

A subrange type is a range of values from an ordinal type (the host type). To define a subrange type, one must specify it's limiting values: the highest and lowest value of the type.


Subrange types

syntdiag1258

Some of the predefined integer types are defined as subrange types:
listing1205
But you can also define subrange types of enumeration types:
listing1207

Real types

Free Pascal uses the math coprocessor (or an emulation) for all its floating-point calculations. The Real native type is processor dependant, but it is either Single or Double. Only the IEEE floating point types are supported, and these depend on the target processor and emulation options. The true Turbo Pascal compatible types are listed in table (gif).

  

Type Range Significant digits Sizegif
Single 1.5E-45 .. 3.4E38 7-8 4
Real 5.0E-324 .. 1.7E308 15-16 8
Double 5.0E-324 .. 1.7E308 15-16 8
Extended 1.9E-4951 .. 1.1E4932 19-20 10
Compgif -2E64+1 .. 2E63-1 19-20 8
Table: Supported Real types

Until version 0.9.1 of the compiler, all the Real types are mapped to type Double, meaning that they all have size 8. The SizeOf function is your friend here. The Real type of turbo pascal is automatically mapped to Double. The Comp type is, in effect, a 64-bit integer.


next up previous contents index
Next: Character types Up: Types Previous: Types

Michael Van Canneyt
Fri Sep 25 09:15:40 MEST 1998